package com.itmuch.cloud.comtroller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.itmuch.cloud.user.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@RestController
public class MovieController {

	@Autowired
	private RestTemplate restTemplate;
	
	//这里有个问题注意下，http://microservice-provider-user/simple/不能写成http://localhost:7910/simple/
	@HystrixCommand(fallbackMethod="findByIdFallback")
	@GetMapping("/movie/{id}")
	public User findById(@PathVariable("id") Long id) {
		return restTemplate.getForObject("http://microservice-provider-user/simple/"+id, User.class);
	}
		
	//findByIdFallback
	public User findByIdFallback(Long id) {
		User user = new User();
		user.setId(0l);
		return user;
	}

	
}
